package com.example.mqspring.rabiitmqbasicleverone.rabbitmqProperties;

import com.example.mqspring.utils.RabbitMqUtil;
import com.rabbitmq.client.*;

import java.io.IOException;

public class Consumer extends DefaultConsumer {

    /**
     * @param channel the channel to which this consumer is attached
     */
    public Consumer(Channel channel) {
        super(channel);
    }

    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
        System.out.println("properties:"+properties.toString());
    }

    public static void main(String[] args) {
        Connection connection = RabbitMqUtil.createConnection();
        Channel channel = null;
        try {
            channel = connection.createChannel();
            Consumer consumer = new Consumer(channel);
            String s = channel.basicConsume(RabbitMqUtil.queue, true, consumer);
            channel.basicCancel(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
